package com.note7_6;

import java.io.*;
import java.util.Scanner;

public class CompanyDao extends Thread{

	private Company c;
	public CompanyDao(Company c){
		super();
		this.c = c;
	}
	public CompanyDao(){
		
	}
	
	Scanner in = new Scanner(System.in);
	//反序列化
	public Company showPerson() throws IOException, ClassNotFoundException{
		ObjectInputStream ots = new ObjectInputStream(new FileInputStream("src/com/company.txt"));
		Company c1 = (Company) ots.readObject();
		ots.close();
		System.out.println(c1.toString());
		return c1;
	}
	
	//招聘员工
	public int addPerson_getNumber(Company c){
		
		System.out.println("请输入员工信息");
		System.out.println("员工姓名：");
		String name = in.next();
		System.out.println("该员工年龄：");
		int age = in.nextInt();
		System.out.println("该员工性别：");
		String sex = in.next();
		System.out.println("该员工职务：");
		String duty = in.next();
		System.out.println("该员工工资：");
		int money = in.nextInt();
		Person p = new Person(name,age, sex,duty,money,1);
		return c.addPerson(p);
	}
	
	//输出员工信息
	public void information(Company c){
		System.out.println(c.toString());
	}
	
	//辞退员工
	public void deleteByNumber(Company c){
		System.out.println("输入要辞退的员工工号：");
		int number = in.nextInt();
		c.delete(number);
		System.out.println("已辞退");
	}
	
	//退出，序列化
	public void quit(Company c) throws IOException{
		ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("src/com/company.txt"));
		oos.writeObject(c);
		oos.close();
	}
	
	public void run(){
		
	}
}
